package com.zang.blogz.config.satoken;

import cn.dev33.satoken.stp.StpInterface;
import cn.dev33.satoken.stp.StpUtil;
import com.zang.blogz.result.Result;
import com.zang.blogz.service.ResourceService;
import com.zang.blogz.service.RoleResourceService;
import com.zang.blogz.service.UserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 自定义权限认证
 *
 * @author 臧臧 on 2022/6/17
 */
@Component
public class StpInterfaceImpl implements StpInterface {

    @Autowired
    @Lazy
    private RoleResourceService resourceService;
    @Autowired
    @Lazy
    private UserRoleService userRoleService;
    @Override
    public List<String> getPermissionList(Object o, String s) {


        Integer userId = Integer.parseInt(o.toString());

        return resourceService.getResourceByLoginAdmin(userId);
    }

    @Override
    public List<String> getRoleList(Object o, String s) {

        Integer userId = Integer.parseInt(o.toString());

        return userRoleService.getRoleByLoginAdmin(userId);
    }
}